package com.kratos.designdemo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author kratos
 * @date 2022-06-09 13:43:55
 */
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {

    WAIT_PAY(0, "待支付"),
    PAID(1, "支付"),
    WAIT_RECEIVE(2, "待收货"),

    //.....其它业务状态，略

    COMPLETED(3, "完成");

    private int code;
    private String name;

    /**
     * 判断枚举是否存在
     *
     * @param code
     * @return
     */
    public static boolean isExtisCode(int code) {
        String name = getValueByCode(code);
        return null == name ? true : false;
    }

    /**
     * 获取枚举值
     *
     * @param code
     * @return
     */
    public static String getValueByCode(int code) {
        OrderStatusEnum[] values = OrderStatusEnum.values();
        for (OrderStatusEnum enums : values) {
            if (code == enums.getCode()) {
                return enums.getName();
            }
        }
        return null;
    }
}
